package com.xiaotu.dao.pgsql;

import com.xiaotu.entity.TvDeleteRecordModel;
import com.xiaotu.entity.TvModel;
import com.xiaotu.entity.TvProcessDataModel;
import com.xiaotu.entity.WorksAwardModel;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import tk.mybatis.mapper.common.BaseMapper;

import java.util.List;


/**
 * @author zhangxiao
 * @create 2021-09-22 11:15
 */
public interface PgsqlTvMapper extends BaseMapper<TvModel> {

    @Select("<script>" +
            " SELECT  " +
            "  t1.tvid,  " +
            "  t2.tvname,  " +
            "  array_to_string(t2.alias,',') alias,  " +
            "  t1.sets,  " +
            "  t2.releasetime,  " +
            "  array_to_string(t2.actor,',') actor,  " +
            "  array_to_string(t2.director,',') director,  " +
            "  array_to_string(t2.screenwriter,',') screenwriter,  " +
            "  array_to_string(t1.producer,',') producer,  " +
            "  t1.area,  " +
            "  array_to_string(t1.productioncompany,',') productioncompany,  " +
            "  array_to_string(t1.issuingcompany,',') issuingcompany,  " +
            "  t1.background,  " +
            "  t1.introduction,  " +
            "  t1.imageurl,  " +
            "  t1.awards,  " +
            "  t2.firstplaytime,  " +
            "  array_to_string(t1.shootaddress,',') shootaddress,  " +
            "  t1.original,  " +
            "  array_to_string(t1.label,',') as label,  " +
            "  t2.showtype,  " +
            "  t1.subject,  " +
            "  array_to_string(t2.platform,',') platform,  " +
            "  t1.copyright,  " +
            "  t1.createtime,  " +
            "  t1.lastupdatetime,  " +
            "  t2.tvtype,  " +
            "  t1.timelength,  " +
            "  t1.uniquename,  " +
            "  t1.repeat,  " +
            "  array_to_string(t1.feature,',') feature,  " +
            "  array_to_string(t1.contacts,',') contacts,  " +
            "  t1.email,  " +
            "  t1.weibourl,  " +
            "  t1.datastate,  " +
            "  array_to_string(t1.publisher,',') publisher,  " +
            "  array_to_string(t1.superintended,',') superintended,  " +
            "  array_to_string(t1.issue,',') issue,  " +
            "  array_to_string(t1.topic,',') topic,  " +
            "  t1.budget,  " +
            "  t1.gross,  " +
            "  t1.open_wkd,  " +
            "  t1.make_status,  " +
            "  t1.update_log,  " +
            "  array_to_string(t2.sellcompany,',') sellcompany,   " +
            "  t1.presenter,  " +
            "  t1.datasourceid,  " +
            "  t1.baikeurl,  " +
            "  t1.doubanurl    " +
            " FROM  " +
            "  basicinfo.tab_tv_info_to_tencent t2  " +
            "  INNER JOIN basicinfo.tab_tv_info t1 ON t1.tvid = t2.tvid   " +
            " WHERE  " +
            "  t1.lastupdatetime :: DATE = '${date}' " +
            "</script>")
    List<TvModel> needSyncs(@Param("date") String date);

    @Select("SELECT * FROM basicinfo.tab_works_award")
    List<WorksAwardModel> getTvAwards();

    @Select("<script>" +
            " SELECT  " +
            "  tv_id tvid,  " +
            "  platform,  " +
            "  play_count playcount,  " +
            "  heat,  " +
            "  db_score dbscore,  " +
            "  collect_time collecttime   " +
            "FROM  " +
            "  basicinfo.tab_tv_process_data   " +
            "WHERE  " +
            "  collect_time :: DATE = '${specifyDate}' " +
            "</script>")
    List<TvProcessDataModel> getTvProcessData(@Param("specifyDate") String specifyDate);

    @Select("<script>" +
            " SELECT * FROM basicinfo.tab_tv_delete_record " +
            "</script>")
    List<TvDeleteRecordModel> getTvDeleteRecords();

    @Select("<script>" +
            " SELECT  " +
            "  tv_id tvid,  " +
            "  platform,  " +
            "  play_count playcount,  " +
            "  heat,  " +
            "  db_score dbscore,  " +
            "  collect_time collecttime   " +
            "FROM  " +
            "  basicinfo.tab_tv_process_data ORDER BY id limit #{pageSize} offset #{pageNum}*#{pageSize} " +
            "</script>")
    List<TvProcessDataModel> getLimitTvProcessData(@Param("pageNum") Integer pageNum, @Param("pageSize") Integer pageSize);
}
